package com.cskaoyan.controller.wx_footprint_controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.footprintBO.FootPrintDelBO;
import com.cskaoyan.bean.footprintVO.FootPrintVO;
import com.cskaoyan.bean.wx_userindexVO.UserIndexVO;
import com.cskaoyan.service.footprint_service.FootPrintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈泉江
 * @version 1.0
 * @description: 足迹模块
 * @date 2021/6/7 15:50
 */

@RestController
@RequestMapping("/wx/footprint/")
public class FootPrintController {

    User user = new User();


    @Autowired
    FootPrintService footPrintService;

    @RequestMapping("list")
    public BaseRespVo footprintList(Integer page, Integer size) {

        User user;
        Subject subject = SecurityUtils.getSubject();
        Object subjectPrincipal = subject.getPrincipal();
        if (subjectPrincipal == null) {
            return BaseRespVo.fail("请登录后查看");
        } else {
            user = (User) subjectPrincipal;
        }

        Integer userId = user.getId();
        FootPrintVO footPrintVO = footPrintService.list(userId, page, size);

        return BaseRespVo.ok(footPrintVO);

    }

    @RequestMapping("delete")
    public BaseRespVo footprintDel(@RequestBody FootPrintDelBO delBO) {
        int code = footPrintService.footprintDel(delBO.getId());

        if (code == 1) {
            return BaseRespVo.ok();
        } else {
            return BaseRespVo.fail();
        }
    }
}
